package com.sang.service.impl;

import com.sang.mapper.UserMapper;
import com.sang.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import javax.servlet.http.HttpServletRequest;

@Service
public class UserServiceImpl {
    @Autowired
    private UserMapper userMapper;

    public User queryById(@PathVariable("id") String username, HttpServletRequest request) {

        String name = request.getHeader("name");

        System.out.println(name);

        System.out.println("调用UserServiceImpl的服务端口");
        //测试Hystrix熔断器是否生效
        if (username.equals("sang")) {
            throw new RuntimeException("自定义Hystrix异常测试....");
        }

        return userMapper.findById(username);
    }
}
